package com.hottop.web.controller.system;

import com.hottop.common.core.domain.AjaxResult;
import com.hottop.common.core.redis.RedisCache;
import com.hottop.system.domain.vo.NameAndValueVO;
import com.hottop.system.service.*;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 主页控制器
 *
 * @author yyq
 * @date 2022-03-02
 */
@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private ITBaiduhotService tBaiduhotService;

    @Autowired
    private ITJinrihotService tJinrihotService;

    @Autowired
    private ITWeibohotService tWeibohotService;

    @Autowired
    private ITTxhotService tTxhotService;

    @Autowired
    private ICommentService commentService;

    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询热搜总数
     */
    @GetMapping("/count")
    public AjaxResult getcount() {
        List<NameAndValueVO> hotcountdata= new ArrayList<>();
        NameAndValueVO bd = new NameAndValueVO();
        bd.setName("百度热搜");
        bd.setValue(tBaiduhotService.getCount());
        NameAndValueVO jr = new NameAndValueVO();
        jr.setName("今日头条");
        jr.setValue(tJinrihotService.getCount());
        NameAndValueVO tx = new NameAndValueVO();
        tx.setName("腾讯新闻");
        tx.setValue(tTxhotService.getCount());
        NameAndValueVO wb = new NameAndValueVO();
        wb.setName("微博热搜");
        wb.setValue(tWeibohotService.getCount());
        hotcountdata.add(wb);
        hotcountdata.add(tx);
        hotcountdata.add(jr);
        hotcountdata.add(bd);
        return AjaxResult.success(hotcountdata);
    }



    /**
     * 查询热搜总数
     */
    @GetMapping("/newadd")
    public AjaxResult getYesterdayAdd() {
        List<NameAndValueVO> yesterdayAdd= new ArrayList<>();
        NameAndValueVO bd = new NameAndValueVO();
        bd.setName("百度热搜");
        bd.setValue(tBaiduhotService.getYesterdayAddCount());
        NameAndValueVO jr = new NameAndValueVO();
        jr.setName("今日头条");
        jr.setValue(tJinrihotService.getYesterdayAddCount());
        NameAndValueVO tx = new NameAndValueVO();
        tx.setName("腾讯新闻");
        tx.setValue(tTxhotService.getYesterdayAddCount());
        NameAndValueVO wb = new NameAndValueVO();
        wb.setName("微博热搜");
        wb.setValue(tWeibohotService.getYesterdayAddCount());
        yesterdayAdd.add(wb);
        yesterdayAdd.add(tx);
        yesterdayAdd.add(jr);
        yesterdayAdd.add(bd);
        return AjaxResult.success(yesterdayAdd);
    }

    /**
     * 查询评论总数
     */
    @GetMapping("/countcomment")
    public AjaxResult getCountComment() {
        return AjaxResult.success(commentService.getCount());
    }

    /**
     * 查询用户总数
     */
    @GetMapping("/countuser")
    public AjaxResult getCountUser() {
        return AjaxResult.success(sysUserService.getCount());
    }

    /**
     * 获取评价平均值
     */
    @GetMapping("/avgrate")
    public AjaxResult getAvgRate() {
        return AjaxResult.success(commentService.getAvgRate());
    }

    /**
     * 获取今日新增用户
     */
    @GetMapping("/newadduser")
    public AjaxResult newAddUser() {
        return AjaxResult.success(sysUserService.getNewAddCount());
    }

    /**
     * 获取今日新增用户
     */
    @GetMapping("/newaddcomment")
    public AjaxResult newAddComment() {
        return AjaxResult.success(commentService.getNewAddComment());
    }

}
